#发起一个请求
import requests
#请求登录
ip="http://192.168.13.172:8080"
mydata={"username":"admin","password":"123456"}
r=requests.post(f"{ip}/login",data=mydata)
print(r.json())
myJSON=r.json()
#提取token
token=myJSON["Admin-Token"]
# print(token)

myheader={"Admin-Token":token}
#区分Text、json、content的区别
#分别打印r中的内容
# print(r.json())
# print(r.text)
# print(r.content)
#实现登录、日志（5个）
#文件上传
#普通键值对
fileData={"type":"img"}

#定义文件参数：'message_img'键来自抓包时的name对应的值，
#值是通过数组的形式传值，第一个参数是抓包时的'filename'对应的值，
#                      第二个参数是通过open打开一个文件，且是二进制读的形式，
#      第三个参数是抓包时的文件类型
furl=r"D:\work\softp\python\APIAuto\datas\1.png"
fileD={"file":(
       "1.png",
        open(furl,"rb"),
        "image/jpeg")
}
mydata={"username":"admin","password":"123456"}
r=requests.post(f"{ip}/file/upload",data=fileData,headers=myheader,files=fileD)
print(r.json())
#新增日志
code={
      "categoryId": "1",
      "content": "这里是今日内容的修改~~",
      "tomorrow": "这里明日工作计划的修改~",
      "question": "这里是今日遇到的问题的修改",
      "batchId": "a6522a16cc407ef091adb0b1a9a93949",
      "sendUserIds": "3,4",
      "sendDeptIds": "",
      "customerIds": "",
      "contactsIds": "",
      "businessIds": "",
      "contractIds": ""
        }

r=requests.post(f"{ip}/OaLog/addOrUpdate",json=code,headers=myheader)
print(r.json())
#获取日志
code={
  "page": 1,
  "limit": 5,
  "by": "1"
}
r=requests.post(f"{ip}/OaLog/queryList",json=code,headers=myheader)
# print(r.json())
# rList=r.json()["data"]["list"]
# ls=[]
# for i in rList:
#     ls.append(i["logId"])
# print(ls)
#取第一个logid
id=r.json()["data"]["list"][0]["logId"]
print(id)
#修改日志
code={
  "logId": 5,
  "categoryId": "1",
  "content": "11111111111",
  "tomorrow": "aaaaaaaaaaaaaaaadddddddddd",
  "question": "11111111111",
  "batchId": "09c2766c7f1afa2c037d156497cc1f6e",
  "sendUserIds": "",
  "sendDeptIds": "",
  "customerIds": "",
  "contactsIds": "",
  "businessIds": "",
  "contractIds": ""
}
r=requests.post(f"{ip}/OaLog/addOrUpdate",json=code,headers=myheader)
print(r.json())
#删除日志
mydata={"logId":id}
r=requests.post(f"{ip}/OaLog/deleteById",data=mydata,headers=myheader)
print(r.json())